package com.css.contentcenter.study.controller;


import com.css.contentcenter.study.feignClient.UserCenterFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author css
 * @since 2019-12-08
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private UserCenterFeignClient centerFeignClient;

    @RequestMapping("index")
    public String test() {
//        List<ServiceInstance> user_center = discoveryClient.getInstances("user-center");
//        List<String> collect = user_center.stream()
//                .map(instance -> {
//                    return instance.getUri() + "/user/id?id={id}";
//                }).collect(Collectors.toList());
//        int i = ThreadLocalRandom.current().nextInt(collect.size());
//        String forObject = restTemplate.getForObject("http://user-center/user/id?id={id}", String.class, "1");
//        System.out.println(forObject);
        String forObject = centerFeignClient.getId("1");
        return forObject;
    }
}

